//


//导航锚点滑动特效

const Anchor = $(".anchor");

$(".anchor").click(function () {
  $("html, body").animate(
    { scrollTop: $($(this).attr("href")).offset().top - 60 + "px" },
    1000
  );

  return false; //不要这句会有点卡顿
});




// 注册页面

$(function () {
  //第一页的确定按钮
  $("#btn_part1").click(function () {
    if (!verifyCheck._click()) return;
    $(".part1").hide();
    $(".part2").show();
    $(".step li").eq(1).addClass("on");
  });
  //第二页的确定按钮
  $("#btn_part2").click(function () {
    if (!verifyCheck._click()) return;
    $(".part2").hide();
    $(".part3").show();
  });
  //第三页的确定按钮
  $("#btn_part3").click(function () {
    if (!verifyCheck._click()) return;
    $(".part3").hide();
    $(".part4").show();
    $(".step li").eq(2).addClass("on");
    countdown({
      maxTime: 10,
      ing: function (c) {
        $("#times").text(c);
      },
      after: function () {
        window.location.href = "my.html";
      },
    });
  });
});
function showoutc() {
  $(".m-sPopBg,.m-sPopCon").show();
}
function closeClause() {
  $(".m-sPopBg,.m-sPopCon").hide();
}

//景点推荐
new CBPFWTabs(document.getElementById("tabs"));

//酒店推荐
$(document).ready(function (e) {
  $(".cntl").cntl({
    revealbefore: 300,
    anim_class: "cntl-animate",
    onreveal: function (e) {
      console.log(e);
    },
  });
});

// 数据展示
let nCount = (selector) => {
  $(selector).each(function () {
    $(this).animate(
      {
        Counter: $(this).text(),
      },
      {
        // 决定动画将运行多长时间
        duration: 4000,
        // 指示要使用哪个缓动函数进行转换
        easing: "swing",
        //为每个动画元素的每个动画属性调用的函数
        step: function (value) {
          $(this).text(Math.ceil(value));
        },
      }
    );
  });
};

let a = 0;
$(window).scroll(function () {
  let oTop = $(".numbers").offset().top - window.innerHeight;
  if (a == 0 && $(window).scrollTop() >= oTop) {
    a++;
    nCount(".rect > h1");
  }
});



//map地图模块

window.onload = function () {
  var map = new AMap.Map('container', {
      resizeEnable: true,
      zoom: 12,
      center: [110.30, 20.03]
  });
//地图内容
  map.setFeatures(['bg', 'building', 'road', 'point'])
//地图空间
  AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.MapType'],
      function () {
          map.addControl(new AMap.ToolBar());

          map.addControl(new AMap.Scale());
      });
//覆盖物
  var marker = new AMap.Marker({
      position: [118.756376, 32.052573]
  });
  marker.setMap(map);
  var circle = new AMap.Circle({
      center: [118.756376, 32.052573],
      radius: 100,
      fillOpacity: 0.2,
      strokeWeight: 1
  })
  circle.setMap(map);
//自定义窗体
  var infowindow;
  var infoWindowContent = '<div class="infowindow-content"><h3>您好！欢迎进入路线搜索！</h3><span style="color:red;font-size:12px;">(点击右上角的小圆点可快速定位)</span></div>';
  map.plugin('AMap.AdvancedInfoWindow', function () {
      infowindow = new AMap.AdvancedInfoWindow({
          panel: 'panel',
          placeSearch: true,
          asOrigin: true,
          asDestination: true,
          content: infoWindowContent
      });
      infowindow.open(map, [110.33119,20.031971]);
  });

//汽车路线规划
  $('#car').on('click', function () {
      $('.pageShow').slideToggle();
      clearMarker()
      AMap.plugin('AMap.Driving', function () {
          var drving = new AMap.Driving({
              map: map,
              panel: "panel"
          })
          drving.search([
              {keyword: $('#star').val()},
              {keyword: $('#end').val()}
          ]);
      })
  })
//步行路线规划
  $("#riding").on('click', function () {
      $('.pageShow').slideToggle();
      clearMarker()
      var walking = new AMap.Walking({
          map: map,
          panel: "panel"
      });
      walking.search([
          {keyword: $('#cStar').val()},
          {keyword: $('#cEnd').val()}
      ]);
  })
//骑行路线规划
  $('#walk').on('click', function () {
      $('.pageShow').slideToggle();
      clearMarker()
      var riding = new AMap.Riding({
          map: map,
          panel: "panel"
      });
      riding.search([
          {keyword: $('#wStar').val()},
          {keyword: $('#wEnd').val()}
      ]);
  })

  function clearMarker() {
      if (marker) {
          marker.setMap(null);
          marker = null;
      }
      if (infowindow) {
          infowindow.close()
      }
  }

//输入提示
  var autoOptions = new AMap.Autocomplete({
      input: "tipinput"
  });
//城市搜索
  var auto = new AMap.Autocomplete(autoOptions);
  var placeSearch = new AMap.PlaceSearch({
      map: map
  });  //构造地点查询类
  AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
  function select(e) {
      placeSearch.setCity(e.poi.adcode);
      placeSearch.search(e.poi.name);  //关键字查询查询
  }

  $('#show').on('click', function () {
      clearMarker()
      $('.pageShow').slideToggle();
  })

  $('#box').on('click', function () {
      clearMarker()
      $('.pageShow').slideToggle();
      var rectOptions = {
          strokeStyle: "dashed",
          strokeColor: "#333",
          fillColor: "#333",
          fillOpacity: 0.3,
          strokeOpacity: 1,
          strokeWeight: 1
      };
      map.plugin(["AMap.MouseTool"], function () {
          var mouseTool = new AMap.MouseTool(map);
          //通过rectOptions更改拉框放大时鼠标绘制的矩形框样式
          mouseTool.rectZoomIn(rectOptions);
      });
  })
  $('#meter').on('click', function () {
      $('.pageShow').slideToggle();
      map.plugin(["AMap.RangingTool"], function () {
          ruler1 = new AMap.RangingTool(map);
          AMap.event.addListener(ruler1, "end", function (e) {
              ruler1.turnOff();
          });
          var sMarker = {
              icon: new AMap.Icon({
                  size: new AMap.Size(19, 31),//图标大小
                  image: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png"
              })
          };
          var eMarker = {
              icon: new AMap.Icon({
                  size: new AMap.Size(19, 31),//图标大小
                  image: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b2.png"
              }),
              offset: new AMap.Pixel(-9, -31)
          };
          var lOptions = {
              strokeStyle: "solid",
              strokeColor: "#FF33FF",
              strokeOpacity: 1,
              strokeWeight: 2
          };
          var rulerOptions = {startMarkerOptions: sMarker, endMarkerOptions: eMarker, lineOptions: lOptions};
          ruler2 = new AMap.RangingTool(map, rulerOptions);
      });
      //启用自定义样式测距

      ruler1.turnOff();
      ruler2.turnOn();
  })
}


//滑动显示动画

const staggeringOption = {
  delay:400,
  distance: "1000px",
  duration: 800,
  origin: "left",
}
ScrollReveal().reveal(".card, .col, .rect", {...staggeringOption, interval: 450});


//返回顶部

$(document).ready(function () {
  $(".to-top").fadeOut();
  $(window).scroll(function () {
    if ($(window).scrollTop() > 300) {
      $(".to-top").fadeIn(3000);
    } else {
      $(".to-top").fadeOut(2000);
    }
  });

  $(".to-top").click(function () {
    $("html,body").animate(
      {
        scrollTop: 0,
      },
      1000
    );
  });
});


